package com.wanmei.filter;


import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 自定义的logoutFilter
 */
public class SystemLogoutFilter extends LogoutFilter {
    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        Subject subject =getSubject(request,response);
        String redirectUrl =getRedirectUrl(request,response,subject);
        ServletContext context =request.getServletContext();

        try {
            subject.logout();
            context.removeAttribute("error");
        } catch (Exception e) {
            e.printStackTrace();
        }
        issueRedirect(request,response,redirectUrl);
        return false;
    }
}
